package pta;/**
 * @author： li
 * @date： 2022-03-27 18:35
 * @version 1.0
 */
import java.io.*;

public class 考试座位号 {
    static String[][] a;
    static int n;
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException {
        n =Integer.parseInt(in.readLine());
//        System.out.println("n="+n);
        a = new String[n+1][3];
        String[] zkz = new String[n+1];
        for(int i=0;i<n;i++){
        String[] s = in.readLine().split(" ");
        zkz[i] = s[0];
        a[i][0] = s[1];
        a[i][1] = s[2];
        }

        int m = Integer.parseInt(in.readLine());
        String[] c = in.readLine().split(" ");
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++){
                if(c[i].equals(a[j][0])){
            out.write(zkz[j]+" ");
            out.write(a[j][1]);
            out.write("\n");
            break;
                }
            }

        out.flush();
        in.close();
        out.close();
    }
}
